<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/include/commonTaglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>左侧菜单</title>
<style type="text/css">
a {
text-decoration:none;
out-line: none;
color: white;
}
.myul{
  background: #3c96d2;
  position: absolute;
  margin: 0;
  padding: 10px 30px;
  overflow: hidden;
}
ul{
list-style-type:none;
line-height:20px;
width:97%;
padding: 0px 10px
}
li{
line-height:30px;
width:100%;
}
</style>
<script type="text/javascript">
$(function(){
	//初始化菜单
	$.ajax({
		url:'${ctx}/menu/getAuthorizedMenu.do',
		dataType:'JSON',
		type:'POST',
		success:function(data){
			if(data.children){
				for(var i=0;i<data.children.length;i++){
					$('#first').accordion('add', {
						iconCls:"icon-man",
						title: "<span style='color:white;letter-spacing:2px;font-size:14px'>"+data.children[i].text+"<span>",
						content:"<ul class='myul' id='"+data.children[i].id+"'></ul>",
						selected: false
					});	
				 if(data.children[i].children){
					 for(var j=0;j<data.children[i].children.length;j++){
						 createMenus(data.children[i].id,data.children[i].children[j]); 
					 }
				 }
				}
				//设置菜单的鼠标经过事件
				var accordions = $('#first').accordion('panels');
			    for(var i=0; i<accordions.length; i++){
			    	accordions[i].parent().unbind().bind('mouseenter',{title:accordions[i].panel('options').title},function(e){
					$('#first').accordion('select', e.data.title);
				 });
				 } 
			}
		},
		error:function(data){
		$.messager.alert("提示","未知错误，请联系管理员！")	
		}
	})
})
//init 菜单
function createMenus(id,data){
	var isBottomMenu=true;
	if(data.children&&data.children.length>0){
		isBottomMenu=false;
		$("#"+id).append("<li style='list-style-image:url(${ctx}/static/img/menu/pencil.png)'><a href='#' onclick=showSubMenu('"+data.id+"',"+isBottomMenu+",'"+data.path+"','"+data.text+"')>"+data.text+"</a><ul class='subMenu' id='"+data.id+"'></ul></li>");
	}else{
		$("#"+id).append("<li style='list-style-image:url(${ctx}/static/img/menu/man.png)'><a href='#' onclick=showSubMenu('"+data.id+"',"+isBottomMenu+",'"+data.path+"','"+data.text+"')>"+data.text+"</a></li>");
	}
	 if(data.children){
		 for(var i=0;i<data.children.length;i++){
			 createMenus(data.id,data.children[i]);
		 }
	 }
}
function showSubMenu(id,isBottomMenu,path,text){
   $("#"+id).children().each(function(){
	   $(this).toggle();
   });
   if(isBottomMenu){
	   parent.$("#homePage").add
	   if (parent.$('#homePage').tabs('exists', text)){
		   parent.$('#homePage').tabs('select', text);
		} else {
			var url="${ctx}"+path;
			var content = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
			parent.$('#homePage').tabs('add',{
				title:text,
				content:content,
				closable:true
			 });
			 parent.$('#homePage').tabs('select', text);
			 //设置tab选项卡的鼠标经过事件
			 var tabs = parent.$('#homePage').tabs('tabs');
		     for(var i=0; i<tabs.length; i++){
			 tabs[i].panel('options').tab.unbind().bind('mouseenter',{title:tabs[i].panel('options').title},function(e){
				 parent.$('#homePage').tabs('select', e.data.title);
			 });
			 }
		}
   }
}
//调整折叠框的大小
function resize(title,index){
	var selectAccordion= $('#first').accordion('getSelected')[0];
	var selectAccordionUl=selectAccordion.firstChild;
	var height=selectAccordionUl.clientHeight;
	selectAccordion.style.height=height;
}
</script>
</head>
<body>
<div id="first" class="easyui-accordion" 
data-options="fit:true,border:true,animate:false,
onSelect:function(title,index){
resize(title,index);
}" 
style="background:#3c96d2">
</div>
</body>
</html>